package com.Txunda.fxw.ui.activity.law;

import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;


import com.Txunda.fxw.ui.adapter.model.LawModel2;

import java.net.URL;
import java.util.List;
import java.util.Map;

public class DownLoadImageTask extends AsyncTask<String, Void, Drawable> {

	List<LawModel2> list;
	List<Map<String, String>> list_map;

	public DownLoadImageTask(List<Map<String, String>> list_map) {
		super();
		this.list_map = list_map;
	}

	public List<LawModel2> getList() {
		return list;
	}

	public void setList(List<LawModel2> list) {
		this.list = list;
	}

	@Override
	protected Drawable doInBackground(String... params) {
		return loadImageFromNetwork(params[0]);
	}

	@Override
	protected void onPostExecute(Drawable result) {
		for (Map<String, String> temp : list_map) {
			Drawable drawable = loadImageFromNetwork(temp.get("d_pic"));
			list.add(new LawModel2(temp.get("p_id"), temp.get("pic"), drawable, temp.get("name"), temp.get("city_id"),
					temp.get("province_id"), temp.get("district_id"), temp.get("wechat"), temp.get("qq"),
					temp.get("tel"), temp.get("province_name"), temp.get("city_name"), temp.get("district_name"),
					temp.get("z_name")));
			
		}
		

	}

	private Drawable loadImageFromNetwork(String imageUrl) {
		Drawable drawable = null;
		try {
			// ����������ͨ���ڶ�������(�ļ���)���жϣ��Ƿ񱾵��д�ͼƬ
			drawable = Drawable.createFromStream(new URL(imageUrl).openStream(), null);
		} catch (Exception e) {
			Log.d("skythinking", e.getMessage());
		}

		return drawable;
	}

}